package com.xc.common.object;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import org.apache.commons.beanutils.Converter;

public class LocalDateTimeConverter implements Converter {
	@SuppressWarnings("unchecked")
	@Override
	public LocalDateTime convert(Class aClass, Object o) {
        // 如果字符串为null，则返回null
        if(o == null)
            return null;
        // 如果字符串为空格，则返回null
        String str = (String) o;
        if(str.trim().equals(""))
            return null;
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return LocalDateTime.parse(str,formatter);
    }
}
